#pragma once
#include <map>
#include "ZMutexFactory.h"

class ZGlobalMap
{
private:
	ZGlobalMap(void);
	virtual ~ZGlobalMap(void);

public:
	static ZGlobalMap& instance();

public:
	void SetVal(const QString& sKey, const QVariant& val);

	template<typename Type>
	bool GetVal(const QString& sKey, Type& val)
	{
		g_AutoLockerMutex("ZGlobalMap");
		auto it = m_map.find(sKey);
		if (it == m_map.end())
		{
			return false;
		}

		val = it->second.value<Type>();
		return true;
	}

	
	template<typename Type>
	Type GetValT(const QString& sKey)
	{
		Type val;
		if (GetVal(sKey, val))
		{
			return val;
		}
		else
		{
			return Type();
		}
	}

public:
	std::map<QString, QVariant>	m_map;
};


#define g_SetGlobalMapVal(sKey, val) ZGlobalMap::instance().SetVal(sKey, val)
#define g_GetGlobalMapVal(sKey, val) ZGlobalMap::instance().GetVal(sKey, val)
#define g_GetGlobalMapValT ZGlobalMap::instance().GetValT